/*
 * @Author: ChunLai
 * @Date: 2022-06-16 16:53:10
 * @LastEditTime: 2025-07-22 20:04:17
 * @Description: 投保服务 --- 管理公共组件的公共状态 已使用
 * @FilePath: \02.bldinsure\src\store\modules\common.js
 */
const state = {
  /**手机验证码*/
  smsPopShow: false,
  smsCode: "",
  smsChecks: [],
  /**规则校验+字段说明*/
  pop9Label: "提示",
  pop9Desc: "",
  pop9Type: "text",
  noticeAbnormal: false, // 告知选'是'
  /**数组渲染刷新*/
  syrRefresh: true,
  bbrRefresh: true,
  // 条款阅读二次确认（梧桐树）
  clauseSedSure: false,
  /**双录预提示*/
  slPreWarn: false,
};
const getters = {
  smsPopShow: (state) => state.smsPopShow,
  smsCode: (state) => state.smsCode,
  smsChecks: (state) => state.smsChecks,
  syrRefresh: (state) => state.syrRefresh,
  bbrRefresh: (state) => state.bbrRefresh,
  clauseSedSure: (state) => state.clauseSedSure,
  pop9Label: (state) => state.pop9Label,
  pop9Desc: (state) => state.pop9Desc,
  pop9Type: (state) => state.pop9Type,
  noticeAbnormal: (state) => state.noticeAbnormal,
  slPreWarn: (state) => state.slPreWarn,
};
const mutations = {
  SET_STATE_FIELD(state, payload) {
    Object.assign(state, payload);
  },
  SET_SL_PRE_WARN(state, payload) {
    state.slPreWarn = payload;
  },

  SET_SYR_REFRESH(state, payload) {
    state.syrRefresh = payload;
  },
  SET_BBR_REFRESH(state, payload) {
    state.bbrRefresh = payload;
  },
  SET_CLAUSE_SED_SURE(state, payload) {
    state.clauseSedSure = payload;
  },
  CLOSE_FIELD_MEAN(state) {
    state.pop9Desc = "";
  },
  SET_FIELD_MEAN_CONT(state, payload) {
    state.pop9Type = "text";
    state.pop9Label = payload.label;
    state.pop9Desc = payload.desc;
    if (payload.type) {
      state.pop9Type = payload.type;
    }
  },
};
const actions = {
  // 监测告知是否选'是'
  checkNoticeStatus({ state }, datas) {
    if (datas.length === 0) return (state.noticeAbnormal = false);
    const len = datas.length;
    for (let i = 0; i < len; i++) {
      const item = datas[i];
      if (item.impartYesOrNo == "Y" && item.impartRemark) {
        state.noticeAbnormal = true;
        break;
      }
    }
  },
  checkedSmsPhone({ state }, data) {
    const fdobj = state.smsChecks.find((e) => e == data);
    if (!fdobj) {
      state.smsChecks.push(data);
    }
  },
  toBldRemitPage({ rootGetters }) {
    const workNum = rootGetters["insert/workNum"],
      orderNum = rootGetters["insert/orderNum"],
      bldUserId = rootGetters["insert/bldUserId"];
    const url = `${process.env.VUE_APP_BLD_PATH}?workNum=${workNum}&userId=${bldUserId}&orderNum=${orderNum}#/pages/bills/apply`;
    window.location.href = url;
  },
  // 去充值
  toBldRechargePage({ rootGetters }) {
    const workNum = rootGetters["insert/workNum"],
      bldUserId = rootGetters["insert/bldUserId"];
    const url = `${process.env.VUE_APP_BLD_PATH}?workNum=${workNum}&userId=${bldUserId}#/pages/defray/index`;
    window.location.href = url;
  },
};

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions,
};
